package cn.com.ibibj.alignmentService.common.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;
import java.util.UUID;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ApiRequestDTO {
    /**
     * 唯一标识
     */
    private String id;
    /**
     * ip+端口
     */
    private String ipAndPort;
    /**
     * 接口
     */
    private String endpoint;
    /**
     * 参数
     */
    private Map<String, Object> params;
    /**
     * 重试次数
     */
    private int retryCount;
    /**
     * 最大重试次数
     */
    private int maxRetries;

    public ApiRequestDTO(String ipAndPort,String endpoint, Map<String, Object> params, int maxRetries) {
        this.id = UUID.randomUUID().toString();
        this.ipAndPort=ipAndPort;
        this.endpoint = endpoint;
        this.params = params;
        this.retryCount = 0;
        this.maxRetries = maxRetries;
    }

    /**
    * 自增重试次数
    */
    public void incrementRetryCount() { this.retryCount++; }
    /**
    * 判断是否允许重试
    */
    public boolean canRetry() { return retryCount < maxRetries; }
}
